package com.fr.privilege.allocation;

import com.fr.base.StringUtils;
import com.fr.base.XMLable;
import com.fr.base.core.ComparatorUtils;
import com.fr.base.dav.FileNode;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLableReader;

public class FileFrag
  implements XMLable
{
  private static final long serialVersionUID = 5307405323031974800L;
  private String path;
  private boolean isDir = false;

  public FileFrag()
  {
  }

  public FileFrag(String paramString)
  {
    this.path = paramString;
    this.isDir = (!(paramString.endsWith(".cpt")));
  }

  public FileFrag(String paramString, boolean paramBoolean)
  {
    this.path = paramString;
    this.isDir = paramBoolean;
  }

  public String getPath()
  {
    if (StringUtils.isBlank(this.path))
      return null;
    String str = StringUtils.perfectStart(this.path, "/");
    if (this.isDir)
      str = StringUtils.perfectEnd(str, "/");
    return str;
  }

  public void setPath(String paramString)
  {
    this.path = paramString;
  }

  public boolean isDir()
  {
    return this.isDir;
  }

  public void setDir(boolean paramBoolean)
  {
    this.isDir = paramBoolean;
  }

  public FileNode toFileNode()
  {
    return new FileNode(this.path, this.isDir);
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    if (paramXMLableReader.isAttr())
    {
      String str;
      if ((str = paramXMLableReader.getAttr("path")) != null)
        setPath(str);
      if ((str = paramXMLableReader.getAttr("isDir")) != null)
        setDir(Boolean.valueOf(str).booleanValue());
    }
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    paramXMLPrintWriter.startTAG("FileFrag").attr("path", getPath());
    if (isDir())
      paramXMLPrintWriter.attr("isDir", "true");
    paramXMLPrintWriter.end();
  }

  public Object clone()
    throws CloneNotSupportedException
  {
    return ((FileFrag)super.clone());
  }

  public boolean equals(Object paramObject)
  {
    return ((paramObject instanceof FileFrag) && (((FileFrag)paramObject).isDir == this.isDir) && (ComparatorUtils.equals(((FileFrag)paramObject).path, this.path)));
  }

  public String toString()
  {
    return this.path + ((this.isDir) ? "[Dir]" : "");
  }
}